home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / BUTTONS / BUTTONS / BUTNTEST.PAS next >
Pascal/Delphi Source File  |  1991-11-13  |  3KB  |  105 lines

  1. Program ButtonTest;
  2. {***************************************************************************}
  3. {*  Buttons.pas  by Daniel Thomas (CIS: 72301,2164)                        *}
  4. {*                                                                         *}
  5. {*    This code is hereby donated to tbe Public Domain.  Have fun!         *}
  6. {*                                                                         *}
  7. {*  Test program for the Buttons unit.  See that unit for details.         *}
  8. {***************************************************************************}
  9.  
  10. USES WinTypes,WinProcs,WObjects,Buttons;
  11.  
  12. {$R ButnTest.res}
  13.  
  14. Const
  15.   id_Button1 = 201;
  16.   id_Button2 = 202;
  17.  
  18. Type
  19.   tButtonTest=object(tApplication)
  20.     procedure InitMainWindow; virtual;
  21.   end;
  22.  
  23.   pMainWindow=^tMainWindow;
  24.   tMainWindow=object(tWindow)
  25.     Button1 : pSingleBitmapButton;
  26.     Button2 : pMultiBitmapButton;
  27.     Button1Enabled,
  28.     Button2Enabled : bool;
  29.  
  30.     Constructor Init(aParent: pWindowsObject; aTitle: pChar);
  31.     Procedure GetWindowClass(var WndClass :tWndClass); virtual;
  32.     Function GetClassName: pChar; virtual;
  33.     Procedure wmDrawItem(var Msg:tMessage);virtual wm_First+wm_DrawItem;
  34.     Procedure bnButton1(var msg: tMessage); virtual id_first+id_Button1;
  35.     Procedure bnButton2(var msg: tMessage); virtual id_first+id_Button2;
  36.   end;
  37.  
  38. Constructor tMainWindow.Init(aParent: pWindowsObject; aTitle: pChar);
  39.  
  40. begin
  41.   TWindow.Init(aParent,aTitle);
  42.   Button1 := new(pSingleBitmapButton,Init(@self,id_Button1,20,20,false,'BN1'));
  43.   Button2 := new(pMultiBitmapButton,Init(@self,id_Button2,200,20,false,
  44.                  'MultiButtonUp','MultiButtonDown','MultiButtonDis'));
  45.   Button1Enabled := true;
  46.   Button2Enabled := true;
  47. end; {Init}
  48.  
  49. PROCEDURE tMainWindow.GetWindowClass(var WndClass: tWndClass);
  50.  
  51. begin
  52.   TWindow.GetWindowClass(WndClass);
  53.   WndClass.lpszMenuName := 'ButtonTestMenu';
  54. end; {GetWindowClass}
  55.  
  56. FUNCTION tMainWindow.GetClassName: pChar;
  57.  
  58. begin
  59.   GetClassName := 'ButtonTest';
  60. end; {GetClassName}
  61.  
  62. Procedure tMainWindow.wmDrawItem(var Msg:tMessage);
  63.  
  64. begin
  65.   with pDrawItemStruct(Msg.lParam)^ do
  66.     case CtlType of
  67.         odt_Button:
  68.           case CtlID of
  69.               id_Button1 : Button1^.DrawItem(Msg);
  70.               id_Button2 : Button2^.DrawItem(Msg);
  71.           end;
  72.     end;
  73. end; {wmDrawItem}
  74.  
  75. Procedure tMainWindow.bnButton1(var msg: tMessage);
  76.  
  77. begin
  78.   MessageBox(hWindow,'Button 1 clicked - will now either enable or disable the other button','ButtonTest',mb_Ok);
  79.   Button2Enabled := not Button2Enabled;
  80.   EnableWindow(Button2^.hWindow,Button2Enabled);
  81. end; {bnButton1}
  82.  
  83. Procedure tMainWindow.bnButton2(var msg: tMessage);
  84.  
  85. begin
  86.   MessageBox(hWindow,'Button 2 clicked - will now either enable or disable the other button','ButtonTest',mb_Ok);
  87.   Button1Enabled := not Button1Enabled;
  88.   EnableWindow(Button1^.hWindow,Button1Enabled);
  89. end; {bnButton2}
  90.  
  91. Procedure tButtonTest.InitMainWindow;
  92.  
  93. begin
  94.   MainWindow := new(pMainWindow,init(nil,'ButtonTest'));
  95. end; {InitMainWindow}
  96.  
  97. Var
  98.   wButtonTest: tButtonTest;
  99.  
  100. BEGIN
  101.   wButtonTest.Init('ButtonTest');
  102.   wButtonTest.Run;
  103.   wButtonTest.Done;
  104. END.
  105.